import { taskReportInfoAPI, orderAmountAPI, orderCountAPI, skuTopAPI, salesFiguresAPI, regionCollectAPI } from '@/api'
// console.log(dayjs().startOf('year').format('YYYY-MM-DD HH:mm:ss')) // 本月第一天加时分秒
// console.log(dayjs().startOf('month').format('YYYY-MM-DD')) // 本月第一天
// console.log(dayjs().format('YYYY-MM-DD')) // 当前时间
// console.log(dayjs().day(0).format('YYYY-MM-DD')) // 获取最近周日的日期
export default {
  namespaced: true,
  state: {
    time: null, // time.time.end当前时间
    information: {
      total: null, // 工单总数
      completedTotal: null, // 完成数
      cancelTotal: null, // 拒绝总数
      progressTotal: null, // 进行中总数
      workerCount: null, // 工作人数
      repair: null, // 是否是运维工单统计
      date: null // 统计的日期
    },
    amount: null, // 获取请求时间范围之内的总收入
    count: null, // 获取请求时间范围之内的订单总数
    skuTopList: null, // 热销前十商品数据
    salesFigures: null, // 销售趋势图数据
    regionCollect: null // 销售额分布数据
  },
  mutations: {
    SET_TIME(state, payload) {
      state.time = payload
    },
    SET_INFORMATION(state, payload) {
      state.information = payload
    },
    SET_AMOUNT(state, payload) {
      state.amount = payload
    },
    SET_COUNT(state, payload) {
      state.count = payload
    },
    SET_TOP(state, payload) {
      state.skuTopList = payload
    },
    SET_SELES(state, payload) {
      state.salesFigures = {}
      state.salesFigures = payload
    },
    SET_REGION(state, payload) {
      state.regionCollect = {}
      state.regionCollect = payload
    }
  },
  actions: {
    async taskReportInfo({ commit }, payload) {
      const { data } = await taskReportInfoAPI(payload)
      commit('SET_TIME', data)
    },
    async orderAmount({ commit }, payload) {
      const { data } = await orderAmountAPI(payload)
      commit('SET_AMOUNT', data)
    },
    async orderCount({ commit }, payload) {
      const { data } = await orderCountAPI(payload)
      commit('SET_COUNT', data)
    },
    async skuTop({ commit }, payload) {
      const { data } = await skuTopAPI(payload)
      commit('SET_TOP', data)
    },
    async salesFigures({ commit }, payload) {
      const { data } = await salesFiguresAPI(payload)
      commit('SET_SELES', data)
    },
    async regionCollect({ commit }, payload) {
      const { data } = await regionCollectAPI(payload)
      commit('SET_REGION', data)
    }
  }
}

